package com.chixing.ih.module.task.mapper;

import com.chixing.ih.common.IhRepository;
import com.chixing.ih.module.system.pojo.User;
import com.chixing.ih.module.task.mapper.provider.TaskMapperProvider;
import com.chixing.ih.module.task.pojo.Contract;
import com.chixing.ih.module.task.pojo.DTO.ContractDTO;
import com.chixing.ih.module.task.pojo.DTO.TaskDTO;
import com.chixing.ih.module.task.pojo.DTO.TaskShowDTO;
import com.chixing.ih.module.task.pojo.Task;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 目的:
 *
 * @author ：zcw
 * @version: 1.0  2020/9/25 20:04
 */
@Mapper
public interface TaskMapper extends IhRepository<Task> {
    @Override
    @InsertProvider(type = TaskMapperProvider.class, method = "saveOne")
    int insertOne(Task task);

    @DeleteProvider(type = TaskMapperProvider.class, method = "delOne")
    int deleteOne(Long taskId);

    @DeleteProvider(type = TaskMapperProvider.class, method = "delAll")
    int deleteAll(Long userId);

    @UpdateProvider(type = TaskMapperProvider.class, method = "updateOne")
    int updateOne(Task task);

    //查询一条任务，根据id
    @SelectProvider(type = TaskMapperProvider.class, method = "findOne")
    TaskShowDTO findOne(Long id);

    @SelectProvider(type = TaskMapperProvider.class, method = "findTaskOne")
    TaskShowDTO findTaskOne(Long id);


    @SelectProvider(type = TaskMapperProvider.class, method = "getOneTask")
    TaskDTO getOneTask(Long id);

    //查询一个人接受但还在审核中的任务
    @SelectProvider(type = TaskMapperProvider.class, method = "findAccepting")
    @Results(id = "taskMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "isSuerId"),
            @Result(column = "task_title", property = "mandateTitle"),
            @Result(column = "talent_categories", property = "talentCategory"),
            @Result(column = "requirement_description", property = "requirementsDescription"),
            @Result(column = "technology", property = "skillsRequirements"),
            @Result(column = "work_way", property = "operationMode"),
            @Result(column = "salary", property = "salary"),
            @Result(column = "work_cycle", property = "workCycle"),
            @Result(column = "work_place", property = "workPlace"),
            @Result(column = "publishing_name", property = "isSuerName"),
            @Result(column = "publishing_phone", property = "isSuerTelephone"),
            @Result(column = "task_status", property = "taskStatus"),
            @Result(column = "type_status", property = "releaseStatus"),
            @Result(column = "is_deleted", property = "logicalDeletion"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_sign", property = "marked"),
            @Result(column = "is_refresh", property = "refreshing"),
            @Result(column = "receive_task_status", property = "receiveTaskStatus")
    })
    List<TaskShowDTO> findAccepting(Long userId);


    //查询一个人的全部发布但还在审核中的任务
    @SelectProvider(type = TaskMapperProvider.class, method = "findBySendTaskTypeStatus")
    @ResultMap({"taskMap"})
    List<TaskShowDTO> findBySendTaskTypeStatus(Long userId);


    //查询一个人发布但还未被接取的任务
    @SelectProvider(type = TaskMapperProvider.class, method = "findBySendTaskStatus")
    @ResultMap({"taskMap"})
    List<TaskShowDTO> findBySendTaskStatus(Long userId);


    //查看任务申请列表
    @SelectProvider(type = TaskMapperProvider.class, method = "findAllApplication")
    List<Long> findAllApplication(Long taskId);


    //查询一个人全部参与的任务
    @SelectProvider(type = TaskMapperProvider.class, method = "findByReceiveTaskUserId")
    @ResultMap({"taskMap"})
    List<TaskShowDTO> findByReceiveTaskUserId(Long userId);


    //根据任务id查询发起人信息
    @SelectProvider(type = TaskMapperProvider.class, method = "findByTaskId")
    @Results(id = "userMap", value = {
            @Result(id = true, column = "user_id", property = "userId"),
            @Result(column = "user_account", property = "userAccount"),
            @Result(column = "nick_name", property = "nickName"),
            @Result(column = "user_password", property = "userPassword"),
            @Result(column = "user_telephone", property = "userTelephone"),
            @Result(column = "user_status", property = "userStatus"),
            @Result(column = "user_career", property = "userCareer"),
            @Result(column = "user_career_direct", property = "userCareerDirect"),
            @Result(column = "user_position", property = "userPosition"),
            @Result(column = "user_company", property = "userCompany"),
            @Result(column = "user_email", property = "userEmail"),
            @Result(column = "support_num", property = "supportNum"),
            @Result(column = "alipay_account", property = "alipayAccount"),
            @Result(column = "wechat_account", property = "wechatAccount"),
            @Result(column = "qq_account", property = "qqAccount"),
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_deleted", property = "isDeleted")

    })
    User findByTaskId(Long taskId);


    //查询全部任务
    @SelectProvider(type = TaskMapperProvider.class, method = "findAll")
    @Results(id = "taskMaps", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "isSuerId"),
            @Result(column = "task_title", property = "mandateTitle"),
            @Result(column = "talent_categories", property = "talentCategory"),
            @Result(column = "requirement_description", property = "requirementsDescription"),
            @Result(column = "technology", property = "skillsRequirements"),
            @Result(column = "work_way", property = "operationMode"),
            @Result(column = "salary", property = "salary"),
            @Result(column = "work_cycle", property = "workCycle"),
            @Result(column = "work_place", property = "workPlace"),
            @Result(column = "publishing_name", property = "isSuerName"),
            @Result(column = "publishing_phone", property = "isSuerTelephone"),
            @Result(column = "task_status", property = "taskStatus"),
            @Result(column = "type_status", property = "releaseStatus"),
            @Result(column = "is_deleted", property = "logicalDeletion"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_sign", property = "marked"),
            @Result(column = "is_refresh", property = "refreshing"),
            @Result(column = "nick_name", property = "nickName"),
            @Result(column = "user_email", property = "email"),
            @Result(column = "image_url", property = "imgUrl")

    })
    List<TaskShowDTO> findAll(String talentCategories, String workPlace, Long workWay, Integer sort);


    @SelectProvider(type = TaskMapperProvider.class, method = "findCount")
    Integer findCount(Long taskId);

    @InsertProvider(type = TaskMapperProvider.class, method = "insertDelivery")
    Integer insertDelivery(Long taskId, Long userId);

    @SelectProvider(type = TaskMapperProvider.class, method = "taskTotalNumber")
    long taskTotalNumber();

    @SelectProvider(type = TaskMapperProvider.class, method = "contract")
    @Results(id = "contractMaps", value = {
            @Result(id = true, column = "id", property = "contractId"),
            @Result(column = "task_title", property = "mandateTitle"),
            @Result(column = "talent_categories", property = "talentCategory"),
            @Result(column = "salary", property = "salary"),
            @Result(column = "work_cycle", property = "workCycle"),
            @Result(column = "create_time", property = "createTime")
    })
    ContractDTO contract(Long taskId);

    @SelectProvider(type = TaskMapperProvider.class, method = "contracts")
    @Results(id = "contractMap", value = {
            @Result(id = true, column = "id", property = "contractId"),
            @Result(column = "partyA_id", property = "sendTaskUserId"),
            @Result(column = "partyB_id", property = "receiveTaskUserId"),
            @Result(column = "partyA_image_url", property = "partyAImageUrl"),
            @Result(column = "partyB_image_url", property = "partyBImageUrl"),
            @Result(column = "status", property = "status"),
            @Result(column = "create_time", property = "createTime")
    })
    ContractDTO contracts(Long taskId);

    @InsertProvider(type = TaskMapperProvider.class, method = "saveContract")
    Integer saveContract(Contract contract);

    @UpdateProvider(type = TaskMapperProvider.class, method = "updatePartBImg")
    Integer updatePartBImg(Contract contract);

    @SelectProvider(type = TaskMapperProvider.class, method = "taskExist")
    Integer taskExist(Long taskId);

    @SelectProvider(type = TaskMapperProvider.class, method = "contractStatus")
    Integer contractStatus(Long taskId, Long receiveTaskId);

    @SelectProvider(value = TaskMapperProvider.class, method = "findExist")
    Integer findExist(Long taskId, Long userId);

    @SelectProvider(value = TaskMapperProvider.class, method = "getCitys")
    List<String> getCitys();

    @SelectProvider(value = TaskMapperProvider.class, method = "getTalentCategory")
    List<String> getTalentCategory();

}
